package com.cnblogs.leizia.crm.commen;

/**
 * 结果类
 *
 * @author leizi
 * @create 2021-02-14 17:58
 */
public class Result {
    /**
     * 错误码
     */
    private int code;
    /**
     * 状态
     */
    private boolean success;
    /**
     * 消息
     */
    private String msg;

    private Object data;

    public Result() {
        this.code = ErrorCode.SUCCESS.getCode();
        this.data = null;
        this.success = true;
        this.msg = ErrorCode.SUCCESS.getMsg();
    }

    public Result(Object data) {
        this.code = ErrorCode.SUCCESS.getCode();
        this.success = true;
        this.msg = ErrorCode.SUCCESS.getMsg();
        this.data = data;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    /**
     * 执行成功结果
     *
     * @return
     */
    public static Result successResult() {
        return new Result();
    }

    /**
     * 执行成功并反回数据
     * @param data
     * @return
     */
    public static Result successToDataResult(Object data) {
        return new Result(data);
    }

    /**
     * 执行失败结果
     *
     * @param msg
     * @return
     */
    public static Result errorResult(String msg) {
        Result result = new Result();
        // 暂时不支持返回具体错误码
        result.code = 9999;
        result.success = false;
        result.msg = msg;
        return result;
    }
}
